import time
from gen import generate_predefined_cases, generate_test_case
from alg import Solution

def test_predefined_cases():
    """测试预定义用例"""
    solution = Solution()
    cases = generate_predefined_cases()
    
    print("=== 预定义测试用例 ===")
    for i, (strs, m, n) in enumerate(cases):
        start_time = time.time()
        result = solution.findMaxForm(strs, m, n)
        end_time = time.time()
        
        print(f"测试用例 {i+1}:")
        print(f"输入: strs = {strs}, m = {m}, n = {n}")
        print(f"输出: {result}")
        print(f"运行时间: {(end_time - start_time) * 1000:.2f} ms")
        print()

def test_random_cases():
    """测试随机生成的用例"""
    solution = Solution()
    
    print("=== 随机测试用例 ===")
    for i in range(3):
        strs, m, n = generate_test_case(str_count=10, max_str_length=15)
        
        start_time = time.time()
        result = solution.findMaxForm(strs, m, n)
        end_time = time.time()
        
        print(f"随机测试用例 {i+1}:")
        print(f"输入: strs = {strs}")
        print(f"m = {m}, n = {n}")
        print(f"输出: {result}")
        print(f"运行时间: {(end_time - start_time) * 1000:.2f} ms")
        print()

def performance_test():
    """性能测试"""
    solution = Solution()
    
    print("=== 性能测试 ===")
    test_sizes = [50, 100, 200]
    
    for size in test_sizes:
        strs, m, n = generate_test_case(str_count=size, max_str_length=20, max_m=50, max_n=50)
        
        # 测试基础版本
        start_time = time.time()
        result1 = solution.findMaxForm(strs, m, n)
        time1 = time.time() - start_time
        
        # 测试优化版本
        start_time = time.time()
        result2 = solution.findMaxFormOptimized(strs, m, n)
        time2 = time.time() - start_time
        
        print(f"数组大小: {size}")
        print(f"基础版本: {result1}, 时间: {time1 * 1000:.2f} ms")
        print(f"优化版本: {result2}, 时间: {time2 * 1000:.2f} ms")
        print(f"结果一致性: {'✓' if result1 == result2 else '✗'}")
        print()

def main():
    """主测试函数"""
    print("一和零问题 - 动态规划解决方案测试")
    print("=" * 50)
    
    test_predefined_cases()
    test_random_cases()
    performance_test()

if __name__ == "__main__":
    main()
